package com.wangjie.simple;

/**
 * @author jieshao
 * @date 2022/5/30 11:22
 *
 * 58. 最后一个单词的长度
 */
public class Test08 {
    public static void main(String[] args) {
        String s = "   fly me   to   the moon  ";
        int res = lengthOfLastWord(s);
        System.out.println(res);
    }

    public static int lengthOfLastWord(String s) {
        int index = s.length() - 1;
        while (s.charAt(index) == ' ') {
            index--;
        }
        int len = 0;
        while (index >= 0 && s.charAt(index) != ' ') {
            len++;
            index--;
        }
        return len;
    }
}